
#include "DTOShipAction.h"
#include "Constantes.h"

DTOShipAction::DTOShipAction(std::string& aDeserealizar,std::string owner) : DTO(SHIP_ACTION,owner){
	deserializar(aDeserealizar);
}

DTOShipAction::DTOShipAction(std::string owner,std::string nombre_jugador, Action action, int life_reduce,playElement elementType, int x, int y) : DTO(SHIP_ACTION,owner){
	this->nombre_jugador = nombre_jugador;
	this->action = action;
	this->life_reduce = life_reduce;
	this->elementType = elementType;
	this->x = x;
	this->y = y;
}

std::string DTOShipAction::serializar(){
	std::stringstream retorno;

	retorno << UtilString::TOlenghtStringStringValue(nombre_jugador);
	retorno << UtilString::TOlenghtStringStringValue(action);
	retorno << UtilString::TOlenghtStringStringValue(life_reduce);
	retorno << UtilString::TOlenghtStringStringValue(elementType);
	retorno << UtilString::TOlenghtStringStringValue(x);
	retorno << UtilString::TOlenghtStringStringValue(y);

	return retorno.str();
}

void DTOShipAction::deserializar(std::string& string){
	this->nombre_jugador = UtilString::FROMlenghtStringStringValue(string);
	this->action = (Action)UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	this->life_reduce = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	this->elementType = (playElement)UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	this->x = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
	this->y = UtilString::stringToInt(UtilString::FROMlenghtStringStringValue(string));
}
